// pages/activity/index.js
Page({
  data: {
    activities: [
      {
        id: 1,
        title: "周末徒步活动",
        cover: "/assets/img/message/精品推荐4.jpg",
        organizer: "城旅户外俱乐部",
        time: "2024-01-20 09:00",
        location: "青城山",
        price: "免费",
        participants: 15,
        maxParticipants: 30,
        status: "报名中",
        tags: ["户外", "徒步", "免费"],
        description: "一起探索青城山的美景，呼吸新鲜空气，结交新朋友"
      },
      {
        id: 2,
        title: "美食探店活动",
        cover: "/assets/img/message/精品推荐2.jpg",
        organizer: "美食达人团",
        time: "2024-01-21 18:00",
        location: "春熙路",
        price: "AA制",
        participants: 8,
        maxParticipants: 12,
        status: "报名中",
        tags: ["美食", "探店", "AA制"],
        description: "发现城市隐藏美食，一起品尝各种特色小吃"
      },
      {
        id: 3,
        title: "摄影外拍活动",
        cover: "/assets/img/message/社区动态1.jpg",
        organizer: "摄影爱好者协会",
        time: "2024-01-22 14:00",
        location: "宽窄巷子",
        price: "免费",
        participants: 20,
        maxParticipants: 25,
        status: "已满员",
        tags: ["摄影", "外拍", "免费"],
        description: "学习摄影技巧，拍摄城市美景，提升摄影水平"
      },
      {
        id: 4,
        title: "读书分享会",
        cover: "/assets/img/message/社区动态2.jpg",
        organizer: "读书俱乐部",
        time: "2024-01-23 19:00",
        location: "咖啡厅",
        price: "¥30",
        participants: 12,
        maxParticipants: 20,
        status: "报名中",
        tags: ["读书", "分享", "学习"],
        description: "分享最近读的好书，交流读书心得，扩展知识面"
      }
    ],
    categories: [
      { name: "全部", active: true },
      { name: "户外", active: false },
      { name: "美食", active: false },
      { name: "摄影", active: false },
      { name: "学习", active: false }
    ]
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '城市活动'
    })
  },

  onActivityTap: function(e) {
    const activity = e.currentTarget.dataset.activity
    
    wx.showModal({
      title: activity.title,
      content: `组织者：${activity.organizer}\n时间：${activity.time}\n地点：${activity.location}\n费用：${activity.price}\n参与人数：${activity.participants}/${activity.maxParticipants}\n状态：${activity.status}\n\n${activity.description}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '立即报名',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '报名功能开发中',
            icon: 'none'
          })
        }
      }
    })
  },

  onCategoryTap: function(e) {
    const index = e.currentTarget.dataset.index
    const categories = this.data.categories.map((item, i) => {
      item.active = i === index
      return item
    })
    this.setData({ categories })
    
    wx.showToast({
      title: '筛选：' + categories[index].name,
      icon: 'none'
    })
  },

  onJoinTap: function(e) {
    e.stopPropagation()
    const activity = e.currentTarget.dataset.activity
    
    if (activity.status === "已满员") {
      wx.showToast({
        title: '活动已满员',
        icon: 'none'
      })
      return
    }
    
    wx.showModal({
      title: '确认报名',
      content: `确定要报名参加"${activity.title}"吗？`,
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '报名成功',
            icon: 'success'
          })
        }
      }
    })
  }
})
